using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace LiveLinq.Internal
{
	abstract class ObservableSingleQueryResultBase<TResult, TSource> : QueryResultBase<TSource>, INotifyPropertyChanged, IValueProvider, IValueProvider<TResult>
	{
		protected const string ValueName = "Value";
		protected static PropertyChangedEventArgs _pcValue = new PropertyChangedEventArgs(ValueName);

		protected ObservableSingleQueryResultBase(IEnumerable<TSource> source) : base(source) {}

		#region INotifyPropertyChanged Members

		public event PropertyChangedEventHandler PropertyChanged = delegate { };

		#endregion

		#region IValueProvider Members

		public bool IsReadonly
		{
			get { return true; }
		}

		object IValueProvider.Value
		{
			get { return Value; }
			set { Value = (TResult)value; }
		}

		#endregion

		#region IValueProvider<TResult> Members

		abstract public TResult Value { get; set; }

		#endregion

		protected void OnPropertyChanged(string name)
		{
			OnPropertyChanged(new PropertyChangedEventArgs(name));
		}

		protected void OnPropertyChanged(PropertyChangedEventArgs e)
		{
			PropertyChanged(this, e);
		}
	}
}